package com.gitee.shop.service.impl;

import com.gitee.shop.domain.OrderItem;
import com.gitee.shop.domain.Orders;
import com.gitee.shop.mapper.OrderItemMapper;
import com.gitee.shop.mapper.OrdersMapper;
import com.gitee.shop.service.OrderService;
import org.apache.catalina.servlets.DefaultServlet;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
@Service
@Transactional
public class OrderServiceImpl implements OrderService {
    //注入dao
    @Autowired
    private OrdersMapper ordersMapper;
    @Autowired
    private OrderItemMapper orderItemMapper;

    @Override
    public int deleteByPrimaryKey(String oid) {
        return 0;
    }

    @Override
    public int insert(Orders record) {
        return ordersMapper.insert(record);
    }

    @Override
    public Orders selectByPrimaryKey(String oid) {
        return null;
    }

    @Override
    public List<Orders> selectAll() {
        return null;
    }

    @Override
    public int updateByPrimaryKey(Orders record) {
        return 0;
    }

    @Override
    public List<Orders> selectByUid(Integer uid) {
        return null;
    }

    //生成订单
    @Override
    public void creatOrder(Orders orders) {

        //1 添加订单
        ordersMapper.insert(orders);

        //2 添加订单项
        List<OrderItem> orderItems = orders.getOrderItems();
        //遍历
        for (OrderItem orderItem : orderItems){
            //添加
            orderItemMapper.insert(orderItem);
        }
    }
}
